package com.example.presentation_libary.presentation;

import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.widget.FrameLayout;

import com.example.presentation_libary.R;
import com.example.presentation_libary.constant.DefultConstants;
import com.example.presentation_libary.eventBus.MsgEvent;
import com.example.presentation_libary.interfaces.ScreenAddViewInterFace;
import com.example.presentation_libary.presentationViews.BasePresentionView;
import com.example.presentation_libary.presentationViews.DefaultAuxiliaryScreen;


/**
 * Android 提供了一个叫 Presentation 类，来实现第二屏
 * 继承 Presentation 实现第二屏，相当于一个特殊的弹窗窗口
 * （具体实现）
 * 副屏屏幕演示
 * <p>
 * 辅助屏幕的布局
 * 通过FrameLayout 来切换不同的布局
 */
public class MultiScreenPresentation extends Presentation {
    private String TAG = "MultiScreenPresentation";
    public Context mContext;//上下文
    private FrameLayout fmPage;//副屏根布局

    public MultiScreenPresentation(Context outerContext, Display display) {
        super(outerContext, display);
        this.mContext = outerContext;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_presentation);
        init();
    }


    private void init() {
        fmPage = findViewById(R.id.fmPage);
        initView();
        initEvent();
    }

    private void initView() {
        getWindowWidthAndHeight();
    }

    private void initEvent() {


    }

    private void getWindowWidthAndHeight() {
        int height = getResources().getDisplayMetrics().heightPixels;
        int width = getResources().getDisplayMetrics().widthPixels;
        Log.i(TAG, "=height==" + height + "=width==" + width);
    }

    //注册这边用this
    @Override
    public void show() {
        super.show();
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }


    public void onMsgPresentationBus(MsgEvent mapEvent) {
        Log.i("==onMsgEventBus 回调处理==", mapEvent.toString());
        //默认
        if (DefultConstants.PagePresentation.DEFAULT_AUXILIARY_SCREEN
                .equalsIgnoreCase(mapEvent.getType())) {
            DefaultAuxiliaryScreen defaultAuxiliaryScreen = new
                    DefaultAuxiliaryScreen(mContext, mapEvent.getJson());
            setAddView(defaultAuxiliaryScreen);
            return;
        }
        if (screenAddViewInterFace != null) {
            screenAddViewInterFace.onAddViewAndMsgEventBus(mapEvent, this);
        }
    }

    //移除布局进行添加新的布局
    public void setAddView(BasePresentionView presentionView) {
        fmPage.removeAllViews();
        fmPage.addView(presentionView);
    }

    //接口对象 添加其他view
    public ScreenAddViewInterFace screenAddViewInterFace;

    public void setScreenAddViewInterFace(ScreenAddViewInterFace screenAddViewInterFace) {
        this.screenAddViewInterFace = screenAddViewInterFace;
    }


}
